home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / apps / 514 / i_floyd / i_floyd.txt < prev   
Text File  |  1991-05-11  |  8KB  |  180 lines

  1. --------------------------------------
  2. Program: I_FLOYD.prg
  3. Date   : 11 Apr 91
  4. Author : W.D.Parks
  5. Purpose: View color IMG files in Mono
  6. --------------------------------------
  7.  
  8.                                 I_Floyd
  9.                            from  Dr. Bobware
  10.                      (C) Copyright 1991 W.D. Parks
  11.                           All rights reserved
  12.  
  13.  
  14.        I_Floyd uses the Floyd-Steinberg algorithm to convert a
  15.        color IMG file into a half-toned monochrome image.
  16.        
  17.        This program is a Preview (or demo or beta-release) of a
  18.        new module for MVG that will be on MODULES DISK #2, RSN.
  19.        
  20.        Similar to MVG's pal Floyd, I_Floyd reads a color IMG and
  21.        converts the colors into grey-level values for display on
  22.        a monochrome screen using error diffusion. The results are
  23.        quite striking!
  24.        
  25.        Complete control is yours via the dialog. The familiar YIQ
  26.        and AVG selections are there along with some others.
  27.        For those who are not familiar with MVG's Floyding of Low-
  28.        Rez color pics, we'll cover these points briefly here.
  29.        
  30.        
  31.        I_Floyd processes can be divided into two major steps:
  32.        
  33.        1) Converting a color into a grey value from 0-255
  34.        2) Converting pixels into a final bitimage using the grey values.
  35.        
  36.        
  37.        Converting to grey is done by mapping each color in the palette
  38.        to a different value according to it's associated R,G and B
  39.        intensities.
  40.        The simplest way to do this is to add the three intensities
  41.        together and divide by three, giving an AVERAGE (ie AVG) for
  42.        each palette entry.
  43.        An often better method is to use the same equation that is used
  44.        by the television industry to convert color pictures into a
  45.        black-and-white picture. This is easily done and the results
  46.        are much better than the averaging method.
  47.        
  48.                 ((RED*30) +  (GREEN*59) + (BLUE*11) ) / 100
  49.        
  50.        or, more clearly,  (RED*0.30) + (GREEN*0.59) + (BLUE*0.11)
  51.        
  52.        For a 16 color image, there are 16 palette entries. One for
  53.        each color (but you knew that;). Each color has three values;
  54.        one for RED, one for GREEN and one for BLUE.
  55.        We convert each palette color by whichever method desired, AVG
  56.        or YIQ, and build a map or table of GREY levels.
  57.        
  58.        The standard ST palette uses only three bits for each intensity
  59.        of R,G and B. This is a maximum of 7 for each; not a very wide
  60.        range.
  61.        In I_FLOYD, we first expand this into a larger bandwidth, 0-255.
  62.        We multiply each color by 36, giving us a maximum of 255. This
  63.        is then placed in the grey table.
  64.        
  65.        Conversion to a bitimage is a little more complex but briefly,
  66.        Each grey value is compared with a threshold (128). If the value
  67.        is below 128 we consider it to be BLACK and distribute the remainder
  68.        to the surrounding pixels.  If it is above 128, we consider it to
  69.        be WHITE and also distribute the remainder to the surrounding
  70.        pixels.
  71.        Our "distribution" is divided into four directions. Some goes to
  72.        the pixel to the right (EAST), some goes to the pixel to the right
  73.        and downward (SouthEAST), some goes directly downward (SOUTH) and
  74.        some goes down and to the left (SouthWEST).
  75.        The default allocation is:
  76.        
  77.                                 EAST  :  7/16
  78.                                 S.EAST:  5/16
  79.                                 SOUTH :  3/16
  80.                                 S.WEST:  1/16
  81.  
  82.       Additionally, I_FLOYD offers a sizing factor of x1 or x2.
  83.       [x1] will display the image in it's original dimensions.
  84.       [x2] will enlarge it x2 in both directions, Vert & Horiz.
  85.       
  86.       
  87.       
  88.       
  89.       MVG itself reads only MONOCHROME IMG files. This is well and
  90.       good since most IMG files are monocrome (single plane) anyway.
  91.       No provision was made for color IMGs due the lack of any standard
  92.       for color information. For the longest time, the only program
  93.       that could correctly read a particular color IMG was the program
  94.       that created it in the first place.
  95.       
  96.       As of this writing, several different methods are required for
  97.       reading color IMG's. Some of the formats are very-very close to
  98.       the original DRI specifications for IMG files (of either type),
  99.       while other color IMG formats veer sharply from the documented
  100.       specs.
  101.       
  102.       I_FLOYD makes provisions for a number of these. The default
  103.       settings are for normal "SEPARATE PLANE BLOCKS" and for ATARI/ST
  104.       palette organization (single word entries).
  105.       
  106.       Options are included for interleaved rasters (said to be the format
  107.       of "Hyperpaint") and even for interleaved words (as seen in Degas
  108.       images).
  109.       
  110.       Three (and a half) options exist for palette styles. 
  111.       
  112.       Single Word       (default)            $0777         for RGB
  113.       3-byte triplets                     $07,$07,$07      for R,G,B
  114.       3-word triplets                  $0007,$0007,$0007   for R,G,B
  115.       3-word triplets, range to 1000     "     "     "      "  " " "
  116.       
  117.                                    
  118.       Additionally, some color IMG formats use a signature word or
  119.       longword to identify themselves. At this time, I_FLOYD will
  120.       recognize "XIMG", "STTT" and "CIMG". $0080 is also recognized
  121.       and certain options are pre-set.
  122.       
  123.       
  124.       Since there is no prescribed method of determining all of these
  125.       options automatically, I_FLOYD simply provides the [BUTTONS] for
  126.       manual control. Some signatures will pre-set some options but it
  127.       cannot guarantee 100% success.
  128.       
  129.       
  130.       
  131.       For normal IMG files, [Hue Expanse] should default to 36. This
  132.       expands the normal ST color range from 0-7 to 0-255.
  133.       
  134.       For STTT files, all is normal.
  135.       For XIMG files, [Hue Expanse] defaults to 10.
  136.       For $0080 signatures, the PLANE type should be set to [Leaved Rasters].
  137.       
  138.       
  139.       
  140.       I_FLOYD can read single-plane IMGs (mono), 4-plane IMGs (16 color)
  141.       and 8-plane IMG's (256 color).
  142.       
  143.       
  144.  
  145.       
  146.       Does all this sound confusing? Sure does to me! <grin>
  147.       
  148.       Play with I_FLOYD. I'd include some sample color IMG files but the
  149.       only ones I've seen are  er... uh... well... a bit on the ribald
  150.       side and I wouldn't want to offend anyone.
  151.       
  152.       CHQ BBS has some color IMG's, so does GEnie.
  153.       
  154.       In any event, take a look-see. Let me know what you think would make
  155.       I_FLOYD better. Let me know if you want a specific color IMG format
  156.       supported... 
  157.       
  158.       From all angles, the "STTT" format is the simplest to understand and
  159.       is the most accurate since it leaves nothing to be "assumed".
  160.       It also follows the original DRI specifications as close as possible.
  161.       
  162.       MVG will support this STTT format in any future releases or modules.
  163.       
  164.       
  165.       
  166.       
  167.       
  168.       
  169.       As always with Dr. Bobware's freebee programs, this program may be
  170.       freely distributed as long as this documentation is included and
  171.       as long as neither are modified in any way. (Yepper. That means
  172.       my spelling errors are now etched in stone.)
  173.       
  174.                                                            Bye:Dr. Bob
  175.                                                             11 Apr 91
  176.  
  177.        W. David Parks
  178.            
  179.        CHQ BBS   :  Dr. Bob       (216) 793-9765 12/24 8/n/1 24hrs
  180.        GEnie adrs:  W.Parks3